package com.xxiongb.business.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

import com.xxiongb.business.constant.RoleConstants;


@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
	
	@Override
	public void configure(HttpSecurity http) throws Exception {
		http
		.authorizeRequests()
			.antMatchers(RoleConstants.ROLE_USER_PUBLIC_MATCH).permitAll()
			.antMatchers(RoleConstants.ROLE_USER_ADMIN_MATCH).hasRole(RoleConstants.ROLE_USER_ADMIN)
			.antMatchers(RoleConstants.ROLE_USER_STANDARD_MATCH)
			.hasAnyAuthority(RoleConstants.ROLE_USER_ADMIN,
					RoleConstants.ROLE_USER_GOLD,
					RoleConstants.ROLE_USER_STANDARD);
	}
}
